import { createStore } from "vuex";

export default createStore({
  state: {
    userInfo: JSON.parse(sessionStorage.getItem("useInfo") || "{}"),
    data_theme: "",
    historyMsgList: { data: [], count: 0 },
  },
  getters: {
    userInfo: (state) => state.userInfo,
    data_theme: (state) => state.data_theme,
  },
  mutations: {
    changeUserInfo(state, data) {
      state.userInfo = data;
    },
    data_theme(state, data) {
      state.data_theme = data;
    },
    historyMsgList(state, data) {
      console.log(state, data, "commit");
      state.historyMsgList = data;
    },
  },
  //异步
  actions: {
    EDIT_USER_INFO({ commit }, payload) {
      return new Promise((res) => {
        commit("changeUserInfo", payload || {});
        sessionStorage.setItem("useInfo", JSON.stringify(payload));
        res(200);
      });
    },
    // eslint-disable-next-line no-unused-vars
    async getUserInfo({ commit, dispatch }) {
      try {
        // const { code, data } = await api.getUserInfo();
        // if (code !== 200) return
        // commit(types.USER_INFO, data)
        // commit(types.CONVERSATIONS_LIST, data.conversationsList)
        // dispatch('getSysInfo')
      } catch (error) {
        // console.log(error)
      }
    },
  },
  modules: {},
});
